package com.briup.mt.service.impl;

import com.briup.mt.bean.Article;
import com.briup.mt.bean.Category;
import com.briup.mt.bean.CategoryExample;
import com.briup.mt.dao.CategoryMapper;
import com.briup.mt.service.ICmsArticleService;
import com.briup.mt.service.ICmsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 武文科
 * @description 分类实现
 * @version 1.0
 * @date 2020/12/16 0016 11:14
 */
@Service
public class CmsCategoryServiceImpl implements ICmsCategoryService {
    @Resource
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> query(String name) {
        CategoryExample example =new CategoryExample();
        if(!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%" + name + "%");
        }
        return categoryMapper.selectByExample(example);
    }

    @Override
    public void saveOrUpdate(Category category) {
        if (category.getId() == null) {
            categoryMapper.insert(category);
        }else{
            categoryMapper.updateByPrimaryKey(category);
        }
    }

    @Override
    public void deleteById(long id) {

        categoryMapper.deleteByPrimaryKey(id);
    }
}
